package cn.kgc.shiro02.controller;

import cn.kgc.shiro02.commons.CodeMsg;
import cn.kgc.shiro02.commons.ResponseResult;
import cn.kgc.shiro02.dto.RolePageDTO;
import cn.kgc.shiro02.entity.Role;
import cn.kgc.shiro02.service.RoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/6
 * @Description:
 */
@Api(tags = "角色模块")
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    // all 查询所有角色信息
    @GetMapping("xmselect")
    public ResponseResult renderXmSelect() {
        List<Role> list = roleService.list();
        return new ResponseResult(CodeMsg.SUCCESS, null, list);
    }

    //角色信息分页数据
    @GetMapping("page")
    public ResponseResult getRolePage(RolePageDTO rolePageDTO) {

        return roleService.selectRolePage(rolePageDTO);
    }


    // 根据角色id  查询角色拥有权限 实现数据回显
    @GetMapping("selectPermissionByRoleId")
    public ResponseResult selectPermissionByRoleId(Integer roleId) {

        return roleService.selectPermissionByRoleId(roleId);
    }


    @PostMapping("addRolePermission")
    public ResponseResult addRolePermission(Integer roleId, String permissionIds) {

        return roleService.addRolePermission(roleId, permissionIds);
    }

    @PostMapping("saveOrUpdate")
    public ResponseResult saveOrUpdate(Role role) {
        return roleService.saveOrUpdateRole(role);
    }


    // 根据角色id  查询角色详细信息  用于数据回显
    @GetMapping("selectById")
    public ResponseResult selectById(Integer id) {
        Role role = roleService.getById(id);
        return new ResponseResult(CodeMsg.SUCCESS, null, role);
    }

    // 根据角色id  删除角色信息
    @GetMapping("deleteById")
    public ResponseResult deleteById(String ids) {
       return roleService.deleteByIds(ids);
    }

}
